//
//  Little.m
//  LibProduct
//
//  Created by admin on 11/17/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "Little.h"

@implementation Little

@synthesize img;
@synthesize originalPosition;
@synthesize currentPosition;
@synthesize delegate;

static Little *littleInstance=nil;

-(id) init
{
	if(self==[super init])
	{
        self.isTouchEnabled = YES;
        littleInstance=self;
        
    }
    return self;
}

+ (Little*)getLittleInstance
{
    return littleInstance;
}
-(BOOL)isInPieceWithCGPoint:(CGPoint)PValue
{    
    if([self isInsidePointOnRect:img at:PValue])
    {
        return TRUE;
    }
        
    return FALSE;
}

//- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    /// An Edit
//    UITouch* touch = [touches anyObject];
//    CGPoint touchPos = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
//    NSLog(@"Point(%f, %f)", touchPos.x, touchPos.y);
//    
//    BOOL isTouchRight=[self isInsidePointOnRect:img.textureRect at:touchPos];
//    
//    if(isTouchRight==TRUE)
//    {
//        NSLog(@"right");
//        if(delegate && [delegate respondsToSelector:@selector(touchRight:)])
//            [delegate touchRight:self]; 
//    }
//    else
//    {
//      // IF NO is do nothing;
//    }
//}

- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    /// An Edit
    UITouch* touch = [touches anyObject];
    CGPoint touchPos = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
   // NSLog(@"Point(%f, %f)", touchPos.x, touchPos.y);
    
    BOOL isTouchRight=[self isInsidePointOnRect:img at:touchPos];
    
    if(isTouchRight==TRUE)
    {
      //  NSLog(@"right");
        if(delegate && [delegate respondsToSelector:@selector(touchRight::)])
            [delegate touchRight:self:touchPos];
    }
    else
    {
        // IF NO is do nothing;
    }
}

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
    UITouch* touch = [touches anyObject];
    CGPoint touchPos = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
    if(delegate && [delegate respondsToSelector:@selector(touchMove:)])
        [delegate touchMove:touchPos];
}

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch* touch = [touches anyObject];
    CGPoint touchPos = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
    if(delegate && [delegate respondsToSelector:@selector(touchEnd:)])
        [delegate touchEnd:touchPos];
}

- (void) dealloc
{
    [img release];
	[super dealloc];
}

@end
